//Copyright 2011 - Jonathan Allen

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace Granite.Testing
{
	/// <summary>
	/// Assertions for INotifyPropertyChanged
	/// </summary>
	 public class PropertyChangedEventAssert : EventAssert<PropertyChangedEventArgs>
	 {
		  readonly INotifyPropertyChanged m_Source;

		/// <summary>
		/// Creates a new INotifyPropertyChanged assertion
		/// </summary>
		/// <param name="source"></param>
		  public PropertyChangedEventAssert(INotifyPropertyChanged source)
				: base(source)
		  {
			if (source == null)
				throw new ArgumentNullException("source", "source is null.");
			Contract.EndContractBlock();

				m_Source = source;
				m_Source.PropertyChanged += SourceEventFired;
				//m_Source.PropertyChanged += (s, e) => Debug.WriteLine("Property Change: " + e.PropertyName);
		  }

		/// <summary>
		/// Asserts that an event is in the queue and that it has the indicated properties.
		/// </summary>
		/// <param name="propertyName">Expected property name</param>
		/// <returns>This will remove the event from the queue.</returns>
		  public new EventPair<PropertyChangedEventArgs> Expect(string propertyName)
		  {
				var nextEvent = Expect();
				Assert.AreEqual(propertyName, nextEvent.EventArgs.PropertyName, "The wrong property name was set correctly.");
				return nextEvent;
		  }

	 }
}